<template>
  <div class="comment-reply">
    <!-- 导航栏 -->
    <van-nav-bar
    class="nav-reply"
    :title="`${comment.reply_count}条回复`">
      <van-icon
        slot="left"
        name="cross"
        @click="$emit('closePop')"
      />
    </van-nav-bar>
    <!-- /导航栏 -->

    <!-- 当前评论项 -->
    <CommentItem
    :comment="comment"
    />
    <!-- /当前评论项 -->

    <van-cell title="全部回复" />

    <!-- 评论的回复列表 -->
    <CommentList
    :list="commentList"
    :source="comment.com_id"
    :idType="'c'"
    />
    <!-- /评论的回复列表 -->

    <!-- 底部 -->
    <div class="write-comment">
      <van-button
      class="write-btn"
      size="small"
      round
      @click="isReplyPostShow=true"
      >写评论</van-button>
    </div>
    <!-- /底部 -->
    <!-- 弹出层 -->
    <van-popup
      v-model="isReplyPostShow"
      position="bottom"
    >
    <CommentPost
      :target="comment.com_id"
      @postSuccess="handlePostSuccess"
    />
    </van-popup>
  </div>
</template>

<script>
import CommentItem from './comment-item.vue'
import CommentList from './comment-list.vue'
import CommentPost from '@/components/comment-post'
export default {
  name: 'CommentReply',
  components: {
    CommentItem,
    CommentList,
    CommentPost
  },
  props: {
    comment: {
      type: Object,
      required: true
    }
  },
  data () {
    return {
      isReplyPostShow: false,
      commentList: []
    }
  },
  methods: {
    handlePostSuccess (data) {
      this.isReplyPostShow = false
      this.comment.reply_count++
      this.commentList.unshift(data.new_obj)
    }
  }
}
</script>

<style scoped lang="less">
.comment-reply {
  padding-top: 100px;
  padding-bottom: 90px;
  /deep/.nav-reply {
    position: absolute;
    top: 0;
    .van-nav-bar__content {
      position: fixed;
      left: 0;
      right: 0;
      background-color: #fff;
      border-bottom: 1px solid #ccc;
      .van-nav-bar__title, .van-icon-cross {
        color: #333;
      }
    }
  }
  .write-comment {
    display: flex;
    align-items: center;
    justify-content: center;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    text-align: center;
    height: 88px;
    background-color: #fff;
    border-top: 1px solid #ccc;
    .write-btn {
      padding: 0 100px;
    }
  }
}
</style>
